package team.southcat.wsyygh.hospital.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.hospital.mapper.ScheduleMapper;
import team.southcat.wsyygh.hospital.service.ScheduleService;
import team.southcat.wsyygh.model.pojo.hospital.Schedule;
import team.southcat.wsyygh.model.pojo.hospital.ScheduleVo;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "前台排班接口")
@RestController
@RequestMapping("/api/hospital/schedule")
public class ScheduleApiController {

    @Autowired
    private ScheduleService scheduleService;

    //获取可预约排班数据
    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@PathVariable Integer page, @PathVariable Integer limit, @PathVariable String hoscode, @PathVariable String depcode) {
        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@PathVariable String hoscode, @PathVariable String depcode, @PathVariable String workDate) {
        List<ScheduleVo> list = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return Result.ok(list);
    }

    @ApiOperation("获取预约排班信息")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
        ScheduleVo schedule = scheduleService.getByScheduleId(scheduleId);
        return Result.ok(schedule);
    }

    @GetMapping("/getById/{id}")
    public Schedule getById(@PathVariable long id){
        return scheduleService.getById(id);
    }

    @GetMapping("/minusOne/{id}")
    public Boolean minusOne(@PathVariable("id") long id){
        Schedule schedule = scheduleService.getById(id);
        schedule.setBookingSurplus(schedule.getBookingSurplus().intValue() - 1);
        boolean b = scheduleService.updateById(schedule);
        return b;
    }

}
